<%@page contentType="text/html; charset=utf-8" language="java" errorPage="error.jsp"%>
<%@page import="com.greendragon.persistence.domain.User"%>
<%@page import="com.greendragon.persistence.domain.Resource"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions"  prefix="fn"%>

<%
String subtitle = "用户";
String scripts = "/static/js/admin.js?v=0.0.1";
String styles = "/static/css/admin.css?v=0.0.1";
%>
<%@ include file="/include/header.jspf"%>
<script>
$(document).ready(function() {
	new GD.admin.init("account");
});
</script>
<style>

</style>
<body>
<div id="wrap">
<div id="content">
  <%@include file="include/body-header.jspf"%>
   <div id="bodier">
		<jsp:include page="include/adminmenu.jspf"/>
		<div id="body-content">
			<div id="content-wrap">
				<div class="icon32 account-icon"></div>
				<h2 class="title">用户</h2>
				<a href="account-new.jsp" class="adduser button-white">添加新用户</a>
				<c:if test="${s!=null}">
				<div class="searchText left">搜索 <span>"${s}"</span> 的结果</div>
				</c:if>
				<form action="account.do" class="right" id="user-search" method="get">
					<input type="hidden" name="type" value="${type}"/>
					<input type="text" name="s" class="regular-text radius5" value="${s}"/>
					<input class="button-blue" type="submit" value="搜索用户"/>
				</form>
				<div id="account-num">
					 <a href="account.do"${type=="user"?" class='current'":""}>普通用户<span class="gray"> (${userCount})</span></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="account.do?type=admin"${type=="admin"?" class='current'":""}>管理员<span class="gray"> (${adminCount})</span></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="account.do?type=block"${type=="block"?" class='current'":""}>冻结用户<span class="gray"> (${blockCount})</span></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="account.do?type=inactive"${type=="inactive"?" class='current'":""}>未激活用户<span class="gray"> (${inactiveCount})</span></a>
				</div>
				<c:if test="${fn:length(pageusers)>0}">
				<div class="account-op">
					<select name="action" class="regular-text radius5">
						<option value="-1" selected="selected">批量操作</option>
					<c:choose>
						<c:when test="${type=='all'||type=='admin'}">
						<option value="block">冻结</option>
						</c:when>
						<c:when test="${type=='block'}">
						<option value="deblock">解冻</option>
						<option value="del">彻底删除</option>
						</c:when>
						<c:when test="${type=='inactive'}">
						<option value="active">激活</option>
						<option value="block">冻结</option>
						</c:when>
					</c:choose>
					</select>
					<button class="button-white">应用</button>
				</div>
				<table id="users-table" class="radius5">
					<tr class="table-title">
						<th class="check" valign="center"><input type="checkbox"/></th>
						<th class="username" colspan="2">用户名</th>
						<th class="nickname">昵称</th>
						<th class="role">角色</th>
						<th class="login-time">最后登入时间</th>
						<th class="login-ip">最后登入IP</th>
					</tr>
					<c:forEach items="${pageusers}" var="u">
					<tr>
						<td class="check" valign="center"><input type="checkbox" name="${u.id}"/></td>
						<td class="avatar">
							<c:choose>
							<c:when test="${user.avatar!=null}">
							<img src="${user.avator.url}"/>
							</c:when>
							<c:otherwise>
							<img src="http://www.gravatar.com/avatar/${u.gravatarHash}?s=32"/>
							</c:otherwise>
							</c:choose>
						</td>
						<td class="username" valign="top">
						<c:choose>
							<c:when test="${u.id==user.id}">
								<a href="profile.do" class="nametext">${u.name}</a>
								<div>
									<a href="profile.do">编辑</a>
								</div>
							</c:when>
							<c:otherwise>
								<a href="useredit.do?uid=${u.id}" class="nametext">${u.name}</a>
								<div>
									<a href="useredit.do?uid=${u.id}">编辑</a>
									| <a href="useredit.do?uid=${u.id}">删除</a>
								</div>
							</c:otherwise>
						</c:choose>
						</td>
						<td>${u.displayName}</td>
						<td>
							<c:if test="${u.role=='user'}">普通用户</c:if>
							<c:if test="${u.role=='admin'}">管理员</c:if>
						</td>
						<td><fmt:formatDate value="${u.lastLoginAt}" pattern="yyyy-MM-dd HH:mm"/></td>
						<td>${u.lastLoginIp}</td>
					<tr>
					</c:forEach> 
					<tr class="table-title">
						<th class="check"><input type="checkbox" /></th>
						<th class="username" colspan="2">用户名</th>
						<th class="nickname">昵称</th>
						<th class="role">角色</th>
						<th class="login-time">最后登入时间</th>
						<th class="login-ip">最后登入IP</th>
					</tr>
				</table>
				<div class="account-op left">
					<select name="action" class="regular-text radius5">
						<option value="-1" selected="selected">批量操作</option>
						<option value="block">冻结</option>
					</select>
					<button class="button-white">应用</button>
				</div>
				<%@include file="include/pagenav.jspf"%>
				<div class="clear"></div>
				</c:if>
				<c:if test="${fn:length(pageusers)==0}">
				<div class="error-tip radius5">没有找到符合条件的用户！</div>
				</c:if>
			</div><!-- content-wrap end-->
		</div><!-- body-content end-->
		<div class="clear"></div>
  </div><!-- bodier end-->
</div>
</div>
<%@include file="include/footer.jspf"%>